package com.server.http.handler.impl;

import com.server.conditionenum.HttpReturnStatus;
import com.server.db.DataBaseManager;
import com.server.http.handler.HttpHandler;
import com.server.http.request.HttpRequestMessage;
import com.server.http.response.HttpResponseMessage;
import com.server.mine.net.HttpProtocol;
import com.server.tools.AppData;

/**
* @author	李小布
* @email	397554852@qq.com
* @version	创建时间：2018年10月16日 下午12:07:32
*/
public class AppLoginStatis extends HttpHandler{
	// -1上传参数错误;-2APP不存在;-3数据库异常;-4未知错误;
	@Override
	public void handle(HttpRequestMessage request, HttpResponseMessage response) {
		int failMsg = 0;
		int type = -1; //0-注册 1-登录
		long appid = 0;
		try {
			type =Integer.parseInt(request.getParameter("type"));
			appid = Long.parseLong(request.getParameter("appid"));
			if(!AppData.appMap.containsKey(appid)) failMsg = -2;
		} catch (Exception e) {
			failMsg = -1;
		}
		
		if(failMsg == 0) {
			failMsg = DataBaseManager.GetInstance().AppLoginStatis(appid, type);
		}
		
		if(failMsg >= 0) {
			SetReturnData(response,1,HttpProtocol.APPSTATISLOGIN,HttpReturnStatus.Successed);
		}else {
			SetReturnData(response,failMsg,HttpProtocol.APPSTATISLOGIN,HttpReturnStatus.Failed);
		}
		
	}
}